/**
 * 路径分析
 * @author cqb
 * @class OpenLayers.Control.BufferPointAnalysis
 * @extends OpenLayers.Control
 * @version 1.0
 * @requires OpenLayers/Control.js
 */

OpenLayers.Control.BufferPointAnalysis = OpenLayers.Class(OpenLayers.Control,{
	/**
	 * Property: type {String} 工具类型
	 */
	type : OpenLayers.Control.TYPE_TOOL,

	/**
	 * Property: styleMap OpenLayers.styleMap
	 */
	styleMap : null,

	/**
	 * Property: title {String} 工具按钮提示文字
	 */
	title : "点缓冲分析",
	/**
	 * 代理地址
	 * @property proxy
	 * @type {String}
	 */
	proxy: null,
	/**
	 * 路径分析地址
	 * @property server
	 * @type {String}
	 */
	server: null,
	/**
	 * 中心点
	 * @property center
	 * @type {LonLat}
	 */
	center: null,
	/**
	 * 缓冲半径
	 * @property radius
	 * @type {Float}
	 */
	radius: null,
	
	/**
	 * 绘制的样式
	 * @property routeSymbolizers
	 * @type {Object}
	 */
	routeSymbolizers: {
		"Line" : {
			strokeWidth : 3,
			strokeOpacity : 1,
			strokeColor : "#F0987C",
			strokeDashstyle : "solid"
		}
	},
	/**
	 * 绘制矢量图层
	 * @property layer
	 * @type {Layer}
	 */
	layer: null,
	
	/**
	 * Method: initialize 初始化
	 */
	initialize : function(options) {
		OpenLayers.Control.prototype.initialize.apply(this,arguments);
	},

	/**
	 * Method: activate 控件被触发时设置鼠标手势
	 */
	activate : function() {
		OpenLayers.Control.prototype.activate.apply(this,arguments);
		this.map.layerContainerDiv.style.cursor = "url("
				+ OpenLayers.Util.getRootPath()
				+ "img/bufferpoint.cur),default";
	},
	
	deactivate: function(){
		OpenLayers.Control.prototype.deactivate.apply(this,arguments);
		this.map.layerContainerDiv.style.cursor = this.map.defaultCursor;
		// if(this.vectorlayer){
			// this.vectorlayer.removeAllFeatures();
			// this.map.removeLayer(this.vectorlayer);
			// this.vectorlayer = null;
		// }

	},

	/**
	 * Method: draw
	 */
	draw : function() {
        var symbolizers = {
            "Point": {
                pointRadius: 0,
                fillOpacity: 0,
                strokeWidth: 0,
                strokeOpacity: 0
            }
        };
        var style = new OpenLayers.Style();
        style.addRules([
        new OpenLayers.Rule({symbolizer: symbolizers})]);
        
        var styleMap = new OpenLayers.StyleMap({"default": style});

		this.handler = new OpenLayers.Handler.Point(this, {
			done : this.bufferQuery
		},{
			layerOptions: {
				styleMap: styleMap
			}
		});
		
		var modifyFeature = this.handler.modifyFeature;
		var scope = this;
		this.handler.modifyFeature = function(pixel, drawing){
            modifyFeature.apply(scope.handler, arguments);
            scope.map.layerContainerDiv.style.cursor = "url("+OpenLayers.Util.getRootPath() + "img/bufferpoint.cur),default";
		}
	},
	
	/**
	 * 开始查询 
	 * @method bufferQuery
	 * @param evt {OpenLayers.Event} 事件
	 */
	bufferQuery : function(evt) {
	    console.log(evt);
	    
        var format = new OpenLayers.Format.WKT();
	    var wkt = format.extractGeometry(evt);
        this.queryend(wkt);
        this.deactivate();
	},
	
	/**
	 * 查询结束
	 * @method queryend
	 * @param features {Array} 空间对象
	 */
	queryend: function(features){
		
	},
	
	CLASS_NAME : "OpenLayers.Control.BufferPointAnalysis"
});